"use strict";

const dayjs = require("dayjs");
const axios = require("axios");
const Controller = require("egg").Controller;

class FundCodeController extends Controller {
  async all() {
    const { ctx } = this;
    // ctx.body = 'hi, egg';
    await ctx.render("fundcode/all.html", {
      test: "测试一下",
    });
  }
  async rank() {
    const { ctx } = this;
    let postUrl = `http://fund.eastmoney.com/data/rankhandler.aspx?op=ph&dt=kf&ft=all&rs=&gs=0&sc=rzdf&st=desc&sd=${dayjs().format(
      "YYYY-MM-DD"
    )}&ed=${dayjs().format(
      "YYYY-MM-DD"
    )}&qdii=&tabSubtype=,,,,,&pi=1&pn=50&dx=1&v=${Math.random()}`;
    let response = await axios({
      method: "get",
      url: postUrl,
      headers: {
        Host: "fund.eastmoney.com",
        Referer: "http://fund.eastmoney.com/data/fundranking.html",
        "User-Agent": "ApiPOST Runtime +https://www.apipost.cn",
      },
    });

    let rankDataText = response.data;

    await ctx.render("fundcode/rank.html", {
      test: "测试一下",
      rankDataText: rankDataText,
    });
  }
}

module.exports = FundCodeController;
